package com.shoppingmall.activity.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.zyh.toolslib.base.BaseActivity;
import com.example.zyh.toolslib.utils.MD5;
import com.example.zyh.toolslib.widget.TitleBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.shoppingmall.R;
import com.shoppingmall.adapter.ScanHistoryAdapter;
import com.shoppingmall.bean.CollectGoodsBean;
import com.shoppingmall.bean.ScanHistoryBean;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 2020/3/16
 * 描述：浏览足迹
 */
public class MineScanHistoryActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.rv_content_list)
    RecyclerView rvContentList;
    @BindView(R.id.smart_refresh)
    SmartRefreshLayout smartRefresh;
    @BindView(R.id.rl_cancel_collect)
    RelativeLayout rlCancelCollect;

    private ScanHistoryAdapter mAdapter;
    private List<ScanHistoryBean> mData = new ArrayList<>();
    private List<ScanHistoryBean> selectData = new ArrayList<>();
    private boolean isModifyState;//是否是编辑状态

    @Override
    protected int initLayout() {
        return R.layout.activity_mine_scan_history;
    }

    @Override
    protected void initView() {
        titleBar.setRightText("编辑");
        titleBar.setTitle("浏览足迹");
    }

    @Override
    protected void initData() {
        mData.add(new ScanHistoryBean(true, "今天"));
        mData.add(new ScanHistoryBean(new CollectGoodsBean()));
        mData.add(new ScanHistoryBean(true, "3月16日"));
        mData.add(new ScanHistoryBean(new CollectGoodsBean()));
        mData.add(new ScanHistoryBean(new CollectGoodsBean()));

        mAdapter = new ScanHistoryAdapter(mData);
        rvContentList.setLayoutManager(new LinearLayoutManager(mContext));
        rvContentList.setAdapter(mAdapter);

        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ToastUtils.showShort(position + "");
            }
        });
    }

    @Override
    protected void initEvent() {
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        titleBar.setRightLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectData.clear();
                if (isModifyState) {
                    titleBar.setRightText("编辑");
                    rlCancelCollect.setVisibility(View.GONE);
                    isModifyState = false;
                } else {
                    titleBar.setRightText("完成");
                    rlCancelCollect.setVisibility(View.VISIBLE);
                    isModifyState = true;
                }
                mAdapter.setModifyState(isModifyState);
                mAdapter.notifyDataSetChanged();
            }
        });
        rlCancelCollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for (int i = 0; i < mData.size(); i++) {
                    ScanHistoryBean scanHistoryBean = mData.get(i);
                    if (scanHistoryBean.isChoosed()) {
                        selectData.add(scanHistoryBean);
                    }
                }
                ToastUtils.showShort(selectData.size() + "");
            }
        });
    }
}
